var InfoBar = GameEntity.extend({
  init: function(id, x, y){
    this.id = id;
	this.x = x;
	this.y = y;
	this.barWidth = 156;
	this.barHeight = 25;
	this.sprite = sprites.infobar
	this.message = '';
  }, 
  draw : function (canvas, hero){
	var health = (Math.floor(hero.health) <= 0) ? 0 : Math.floor(hero.health);
	var healthWidth = this.barWidth/hero.maxHealth * health;
	var manaWidth = this.barWidth/hero.maxMana * hero.mana;
	  //ctx.drawImage(this.sprite.image, this.x, this.y);
	canvas.ctx.save();
	canvas.ctx.drawImage(this.sprite.image, 290, 6, 159, 82, this.x + 120, this.y + 8, 159, 82);
	canvas.ctx.fillStyle = '#B00000';
	canvas.ctx.fillRect(this.x + 120, this.y + 8, healthWidth, this.barHeight);
	canvas.ctx.fillStyle = '#003399';
	canvas.ctx.fillRect(this.x + 120, this.y + 47, manaWidth, this.barHeight);
	canvas.ctx.drawImage(this.sprite.image, 0, 0, 288, 82, this.x, this.y, 288, 82);
	canvas.ctx.font = "10px arial";
	canvas.ctx.textAlign = 'center';
	canvas.ctx.fillStyle = '#dddddd';
	canvas.ctx.shadowColor = '#444444'
	canvas.ctx.shadowOffsetX = 1;
	canvas.ctx.shadowOffsetY = 1;
	canvas.ctx.fillText(health + " / " + hero.maxHealth, this.x + 200, this.y + 24);
	canvas.ctx.fillText(Math.floor(hero.mana) + " / " + hero.maxMana, this.x + 200, this.y + 63);
	canvas.ctx.drawImage(hero.defaultSprite.image, 0, hero.h*2, hero.w, hero.h, this.x+8, this.y+3,  hero.w, hero.h);
	canvas.ctx.restore();
	if(this.message){
		this.displayMessage(canvas)
	}
	
  },
  displayMessage: (function (){
	var timesTodisplay = 50; //колко кадъра да се покажа съобщението
	var counter = 1;
	return function(canvas, newCounter){
		counter = newCounter || counter;
		
		canvas.ctx.save();
		canvas.ctx.font = "30px disposabledroid";
		canvas.ctx.textAlign = 'center';
		canvas.ctx.fillStyle = '#b7a457';
		canvas.ctx.fillText(this.message, canvas.width/2, canvas.height*0.97);
		canvas.ctx.restore();
		
		if(++counter > timesTodisplay){
			counter = 1;
			this.message = '';
		}
	  }
  })(),
  setMessage: function(message, canvas, newCounter){
	  counter = newCounter || 1;			//оказва колко дълго да стой съобщението, по подразбиране е 50 - 1
	  this.message = message;
	  this.displayMessage(canvas, counter);
  }
});